import java.awt.Color;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.swing.JPanel;


public class ThreadJbossAlive  extends Thread {
	JPanel p;
	boolean active;
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	public ThreadJbossAlive(JPanel p)
	{
		this.p = p;
	}
	public void run() {
		while(true)
		{


			try {
				HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8080").openConnection();
				connection.setRequestMethod("HEAD");
				int responseCode = connection.getResponseCode();
				if (responseCode != 200) {
					System.out.println("NOT");
				}
				else System.out.println("OK");
				p.setBackground(Color.RED);
				sleep(1000);
				p.setBackground(Color.LIGHT_GRAY);
				sleep(500);
			} catch (java.net.ConnectException e) {
				// TODO Auto-generated catch block
				p.setBackground(Color.LIGHT_GRAY);
				System.out.println("NOT");
			}
			catch (IOException e) {
				// TODO Auto-generated catch block
				System.out.println("NOT");
			}
			catch (InterruptedException e) {
				// TODO Auto-generated catch block
				System.out.println("NOT");
			}
			
		}

	}
	public void distruggi() {
		p.setBackground(Color.LIGHT_GRAY);
		this.stop();
		
	}

}
